package com.example.administrator.wxam;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONException;
import org.json.JSONObject;

public class MainActivity extends AppCompatActivity {
        private Button denLU;
        private EditText ET_yonhumin;
        private  EditText Et_password;

    private  String user_id;
     private String ssn_id;
    String yonhu;
    String mima;
    public String getSsn_id() {
        return ssn_id;
    }

    public void setSsn_id(String ssn_id) {
        this.ssn_id = ssn_id;
    }

    public String getUser_id() {
        return user_id;
    }

    public void setUser_id(String user_id) {
        this.user_id = user_id;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        IntinID();

        yonhu();

        butdinaji();

    }

    private void butdinaji() {
        denLU.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intrnt = new Intent(MainActivity.this,Main2Activity.class);
                startActivity(intrnt);
            }
        });

    }

    private void yonhu() {

        RequestQueue requestQueue = Volley.newRequestQueue(this);
        yonhu = ET_yonhumin.getText().toString();
       mima = Et_password.getText().toString();
        if (yonhu.equals("18885089501")|| mima.equals("qqqqqq")) {
            StringRequest stringRequest = new StringRequest("http://api.gzkbapp.com/postLogin.action?userName=" + yonhu + "&userPswd=" + mima + "&vrfCd=1&cltId=1", new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    JSONObject jsonObject = null;
                    try {
                        jsonObject = new JSONObject(response);
                        String caty = jsonObject.getString("rtn_msg");
                       user_id = jsonObject.getString("user_id");
                       ssn_id = jsonObject.getString("ssn_id");


                        Toast.makeText(MainActivity.this, caty, 0).show();
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            });
            requestQueue.add(stringRequest);
            requestQueue.start();
        }else {
            Toast.makeText(MainActivity.this,"用户名或者密码出错",0).show();

        }

    }

    private void IntinID() {
        denLU = (Button) findViewById(R.id.but_denlu);
        ET_yonhumin = (EditText) findViewById(R.id.yonhumin);
        Et_password = (EditText) findViewById(R.id.mima);

    }
}
